﻿using System;
using System.Collections.Generic;
using BSpec.Conventions;

namespace BSpec.Specification
{
    public class Behaviour : SpecificationElement
    {
        private readonly List<Observation> _observations = new List<Observation>();
        
        protected Behaviour(string name)
            : base(name)
        {
        }

        public Observation[] Observations
        {
            get { return _observations.ToArray(); }
        }

        public static Behaviour Create(Type testFixtureType)
        {
            string name = testFixtureType.GetName(NamingConvention.Behaviour);

            return name.IsEmpty() ? new NullBehaviour() : new Behaviour(name);
        }

        public void AddObservationsFor(Type testFixtureType)
        {
            foreach (var testMethod in testFixtureType.GetTestMethods())
            {
                var observation = Observation.Create(testMethod);
                _observations.Add(observation);
            }
        }
    }

    public class NullBehaviour : Behaviour
    {
        public NullBehaviour()
            : base(string.Empty)
        {
        }
    }
}